//
//  NetworkTaskManager.swift
//  OneDay
//
//  Created by xicheng on 16/11/15.
//  Copyright © 2016年 xicheng. All rights reserved.
//

import UIKit

class NetworkTaskManager: NSObject {

  
  static let sharedInstance = NetworkTaskManager()
  
  static var lock:Int = 0
  
  private override init(){}
  
  private var taskArray:[NetworkTask] = [NetworkTask]()
  

  func appendTask(_ task:NetworkTask){
    taskArray.append(task)
    TXLogDebug("网络任务队列Count:\(taskArray.count)__description:\(self)")
  }
  
  
  func removeTask(_ task:NetworkTask){
    objc_sync_enter(NetworkTaskManager.lock)
    let count = taskArray.count
    if count > 0 {
      for index in 0 ..< count {
        if task == taskArray[index] {
          taskArray.remove(at: index)
          TXLogDebug("网络任务队列Count:\(taskArray.count)__移除Task:\(task)")
          break
        }
      }
    }
    objc_sync_exit(NetworkTaskManager.lock)
  }
  
}



class ResponseProxy:NSObject {
  
  var response:Any?
  
  
  static func proxyResponse(_ response:Any?)->ResponseProxy{
    let instance = ResponseProxy()
    instance.response = response
    return instance
  }
  
}
